﻿Namespace Helpers

    Public Class MeldingenHelper

        Public Shared Function MoetMeldingGetoondWorden() As Boolean
            Dim winkelier As ArtikelsDataSet.WinkeliersRow = GetWinkelier()
            Dim idLaatsteMelding As Integer = (From m In Utility.Data.Meldingen _
                                          Select m.Id).Max()
            Return (winkelier.IsIdLaatsteMeldingNull OrElse winkelier.IdLaatsteMelding < idLaatsteMelding)
        End Function

        Public Shared Function GetAndUpdateTeTonenMeldingId() As Integer
            Dim winkelier As ArtikelsDataSet.WinkeliersRow = GetWinkelier()
            Dim idMeldingWinkelier As Integer = 0
            If (winkelier.IsIdLaatsteMeldingNull) Then
                idMeldingWinkelier = (From m In Utility.Data.Meldingen _
                                      Select m.Id).Min()
            Else
                idMeldingWinkelier = (From m In Utility.Data.Meldingen _
                                      Where m.Id > winkelier.IdLaatsteMelding _
                                      Select m.Id).Min()
            End If
            winkelier.IdLaatsteMelding = idMeldingWinkelier
            Dim winkeliersAdapter As New ArtikelsDataSetTableAdapters.WinkeliersTableAdapter()
            winkeliersAdapter.Update(Utility.Data.Winkeliers)
            Return idMeldingWinkelier
        End Function

        Private Shared Function GetWinkelier() As ArtikelsDataSet.WinkeliersRow
            Return (From w In Utility.Data.Winkeliers _
                    Where w.Id = Security.HuidigeWinkelierId).First
        End Function

    End Class

End Namespace
